import scrapy
from allstocksname import g_StockNameDict

class DmozSpider(scrapy.Spider):
    name = "cash"
    allowed_domains = ["10jqka.com.cn"]
    start_urls = []
    
    def __init__(self):
        for key in g_StockNameDict.keys():
            DmozSpider.start_urls.append('http://basic.10jqka.com.cn/%s/xls/cashreport.xls'%(key[2:8]))
            
    def parse(self, response):
        filename = response.url.split("/")[-3]
        if filename[0] == '6':
            filename = "sh" + filename
        else:
            filename = "sz" + filename
            
        filepath = "E:/temp/cash/" + filename        
        with open(filepath, 'wb') as f:
            f.write(response.body)